package com.club.common.exception;

import com.club.entity.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局异常处理
 *
 * @author chaochao(vx : zhangfec)
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(value = CustomException.class)
    public R catchCustomExceptionHandler(CustomException e) {
        e.printStackTrace();
        log.error("自定义异常:{}", e.getMessage());
        return R.error(e.getMessage());
    }


    @ExceptionHandler(value = RuntimeException.class)
    public R handler(RuntimeException e) {
        e.printStackTrace();
        log.error("运行时异常：----------------{}", e.getMessage());
        return R.error(e.getMessage());
    }


    @ExceptionHandler(value = Exception.class)
    public R catchOtherException(Exception e) {
        e.printStackTrace();
        log.error("其他异常:------------------{}", e.getMessage());
        return R.error(e.getMessage());
    }

}
